//
//  UtilsTest.cpp
//  GRE
//
//  Created by Kutlak Roman on 05/03/2012.
//  Copyright (c) 2012 University of Aberdeen. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>

#include <gtest/gtest.h>

#include "Utilities.h"

using namespace kutlak::roman::gre;
using std::string;
using std::vector;


TEST(Utils, SplitString) 
{
    const string str = "this is a string to split.";
    typedef vector<string> Res_t;
    
    Res_t res = SplitString(str);
    
    ASSERT_EQ(6, res.size());
    EXPECT_EQ("this",   res[0]);
    EXPECT_EQ("is",     res[1]);
    EXPECT_EQ("a",      res[2]);
    EXPECT_EQ("string", res[3]);
    EXPECT_EQ("to",     res[4]);
    EXPECT_EQ("split.", res[5]);
    
    const string str2 = "no_split_here";
    
    res = SplitString(str2);
    ASSERT_EQ(1, res.size());
    EXPECT_EQ("no_split_here", res[0]);
    
    res = SplitString(str2, "_");
    ASSERT_EQ(3, res.size());
    EXPECT_EQ("no",    res[0]);
    EXPECT_EQ("split", res[1]);
    EXPECT_EQ("here",  res[2]);
    
}

TEST(Utils, RemoveChars) 
{
    const string str = "<attribute> <value>";
    
    string s = RemoveChars(str, "<");
    EXPECT_EQ("attribute> value>", s);
    
    s = RemoveChars(str, ">");
    EXPECT_EQ("<attribute <value", s);
    
    s = RemoveChars(str, "<>");
    EXPECT_EQ("attribute value", s);
    
}

TEST(Utils, Trim) 
{
    EXPECT_EQ("", Trim(""));
    EXPECT_EQ("a", Trim("a"));
    EXPECT_EQ(" ", Trim(" "));
    EXPECT_EQ(" ", Trim("  "));
    EXPECT_EQ(" ", Trim("   "));
    EXPECT_EQ(" ", Trim("    "));
    EXPECT_EQ("no two spaces", Trim(" no    two  spaces "));
}

